package com.fulin.serivaliable;

import java.io.*;
import java.lang.reflect.Field;

/**
 * @Description TODO
 * @Author fulin16
 * @Date 2020/12/11 11:28
 **/
public class TestSerivaliable {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        TestSerivaliable t = new TestSerivaliable();
        t.derival();
//        t.serival();
    }

    private void serival() throws IOException {
        Person p = new Person();
        p.setName("fulin");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("E:\\a")));
        oos.writeObject(p);
        oos.close();
    }

    private void derival() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("E:\\a")));
        Person person = (Person)ois.readObject();
        System.out.println(person.getName());
    }

    private void getUID() throws NoSuchFieldException, IllegalAccessException {
        Person person = new Person();
        Class clazz = Person.class;
        Field serialVersionUID = clazz.getField("serialVersionUID");
        serialVersionUID.setAccessible(true);
        Long uid = (Long) serialVersionUID.get(person);
        System.out.println(uid);

    }
}
